<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/20
 * Time: 18:13
 */
namespace app\index\model;

use think\Model;

class ApiGroup extends Model
{
    // status属性读取器
    protected function getStatusAttr($value)
    {
        $status = [ 0 => '禁用', 1 => '启用'];
        return $status[$value];
    }

    public function getGroupList($name = '')
    {
        $wh_name = '';
        if($name){
            $wh_name = 'and u.name="'.$name.'"';
        }
        return $this->query('
SELECT g.id,g.name 
FROM api_group g 
INNER JOIN api a ON a.group_id=g.id 
INNER JOIN user u ON u.id=a.user_id 
WHERE g.status=1 AND a.status=1 '.$wh_name.' 
GROUP BY g.id ORDER BY g.id DESC');
    }

}